/*
 * CMediaRender.h
 *
 *  Created on: 2017年3月16日
 *      Author: chuanjiang.zh
 */

#ifndef CMEDIARENDER_H_
#define CMEDIARENDER_H_

#include "MediaRender.h"
#include "MediaFormat.h"
#include "AudioRender.h"
#include "VideoRender.h"
#include "SharedPtr.h"
#include "TCriticalSection.h"
#include "MediaDecoder.h"


namespace av
{

typedef std::shared_ptr< MediaDecoder >	MediaDecoderPtr;

typedef std::shared_ptr< VideoRender >	VideoRenderPtr;
typedef std::shared_ptr< AudioRender >	AudioRenderPtr;



class CMediaRender: public MediaRender
{
public:
	explicit CMediaRender(void* wnd);
	virtual ~CMediaRender();

	virtual int open(const MFormat& fmt);

	virtual void close();

	virtual bool isOpen();

	virtual int write(MPacket& pkt);

	virtual int play();

	virtual int pause();

	virtual void stop();

	virtual void flush();

	virtual int getState();


protected:
	void setState(int state);

protected:
	comn::CriticalSection	m_cs;

	void*	m_wnd;

	MediaFormat	m_format;
	VideoRenderPtr	m_videoRender;
	AudioRenderPtr	m_audioRender;
	StreamState	m_state;

	MediaDecoderPtr	m_videoDecoder;
	MediaDecoderPtr	m_audioDecoder;

};


} /* namespace av */

#endif /* CMEDIARENDER_H_ */
